package com.caiyi.tips.core.aspect;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.caiyi.tips.core.VO.ResultVO;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class SecurityInterceptor extends HandlerInterceptorAdapter{
    /**
     * 重写preHandle方法，在请求发生之前执行
     * 该方法会在Controller的方法执行前会被调用，可以使用这个方法来中断或者继续执行链的处理，当返回true时，处理执行链会继续，当返回false时，则不会去执行Controller的方法。
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
     /*   String url =  request.getRequestURL().toString();
        if(url.indexOf("test")>0){
            return true;
        }
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ResultVO vo =  ResultVO.okDesc("成功");
       // JSON.toJSON(vo);
        out.print(JSON.toJSON(vo));
        out.close();
        return false;*/

      return true;
    }

    /**
     * 重写postHandle方法，在请求完成之后执行
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }

    @Override
    public  void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {


    }
}